<?
/***************************************************************************
*                            Dolphin Smart Community Builder
*                              -------------------
*     begin                : Mon Mar 23 2006
*     copyright            : (C) 2007 BoonEx School
*     website              : http://www.boonex.com
* This file is part of Dolphin - Smart Community Builder
*
* Dolphin is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the
* License, or  any later version.
*
* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Dolphin,
* see license.txt file; if not, write to marketing@boonex.com
***************************************************************************/

bx_import('BxDolTwigTemplate');

/*
 * Schools module View
 */
class BxSchoolsTemplate extends BxDolTwigTemplate {

    var $_iPageIndex = 500;      
    
	/**
	 * Constructor
	 */
	function BxSchoolsTemplate(&$oConfig, &$oDb) {
        parent::BxDolTwigTemplate($oConfig, $oDb);
    }
 
    // ======================= ppage compose block functions 

    function blockDesc (&$aDataEntry) {
        $aVars = array (
			'title' => $aDataEntry['title'],
			'description' => $aDataEntry['desc'],
        );
        return $this->parseHtmlByName('block_description', $aVars);
    }
  
    function blockFields (&$aDataEntry) {
        $sRet = '<table class="modzzz_schools_fields">';
        modzzz_schools_import ('FormAdd');        
        $oForm = new BxSchoolsFormAdd ($GLOBALS['oBxSchoolsModule'], $_COOKIE['memberID']);
        foreach ($oForm->aInputs as $k => $a) {
            if (!isset($a['display']) || !$aDataEntry[$k]) continue;
            $sRet .= '<tr><td class="modzzz_schools_field_name" valign="top">' . $a['caption'] . '<td><td class="modzzz_schools_field_value">';
            if (is_string($a['display']) && is_callable(array($this, $a['display'])))
                $sRet .= call_user_func_array(array($this, $a['display']), array($aDataEntry[$k]));
            else if (0 == strcasecmp($k, 'country'))
                $sRet .= _t($GLOBALS['aPreValues']['Country'][$aDataEntry[$k]]['LKey']);
            else
                $sRet .= $aDataEntry[$k];
            $sRet .= '<td></tr>';
        }
        $sRet .= '</table>';
        return $sRet;
    }
 
    function unit ($aData, $sTemplateName, &$oVotingView) {

       $bExtended = (getParam("modzzz_schools_extended_view")=="on") ? true : false;

        if (null == $this->_oMain)
            $this->_oMain = BxDolModule::getInstance('BxSchoolsModule');

        if (!$this->_oMain->isAllowedView ($aData)) {            
            $aVars = array ('extra_css_class' => 'modzzz_schools_unit');
            return $this->parseHtmlByName('browse_unit_private', $aVars);
        }

        $sImage = '';
        if ($aData['thumb']) {
            $a = array ('ID' => $aData['author_id'], 'Avatar' => $aData['thumb']);
            ////$aImage = BxDolService::call('photos', 'get_image', array($a, 'browse'), 'Search');
            $aImage = BxDolService::call('photos', 'get_image', array($a, 'thumb'), 'Search');

            $sImage = $aImage['no_image'] ? '' : $aImage['file'];
        } 
  
		$sDesc = $aData['desc'];
		$iLimitChars = (int)getParam('modzzz_schools_max_preview');
		if (strlen($sDesc) > $iLimitChars) {
 			$sLinkMore = '...';
			$sDesc = process_line_output(mb_substr(strip_tags($sDesc), 0, $iLimitChars)) . $sLinkMore;
		}

        $sRate = $oVotingView ? $oVotingView->getJustVotingElement(0, $aData['id'], $aData['rate']) : '&#160;';
 
        $aVars = array (            
 
			'bx_if:compact' => array( 
				'condition' =>  (!$bExtended),
				'content' => array(  
					'id' => $aData['id'],
					'thumb_url' => $sImage ? $sImage : $this->getIconUrl('no-photo.png'), 
					'school_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aData['uri'],
					'school_title' => $aData['title'],
					'created' => defineTimeInterval($aData['created']),
					'author' => $aData['NickName'],
					'author_url' => $aData['author_id'] ? getProfileLink($aData['author_id']) : 'javascript:void(0);',
					'fans_count' => $aData['fans_count'] + $aData['students_count'] + $aData['alumni_count'],
					'views_count' => $aData['views'],  
					'country_city' => _t($GLOBALS['aPreValues']['Country'][$aData['country']]['LKey']) . (trim($aData['city']) ? ', '.$aData['city'] : ''), 
					'rate' => $sRate,  

				),  		
			),  
			'bx_if:extended' => array( 
				'condition' =>  ($bExtended),
				'content' => array(  
					'id' => $aData['id'],
					'thumb_url' => $sImage ? $sImage : $this->getIconUrl('no-photo.png'), 
					'school_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aData['uri'],
					'school_title' => $aData['title'],
					'created' => defineTimeInterval($aData['created']),
					'author' => $aData['NickName'],
					'author_url' => $aData['author_id'] ? getProfileLink($aData['author_id']) : 'javascript:void(0);',
					'fans_count' => $aData['fans_count'],
					'views_count' => $aData['views'],  
					'country_city' => _t($GLOBALS['aPreValues']['Country'][$aData['country']]['LKey']) . (trim($aData['city']) ? ', '.$aData['city'] : ''),
 					'rate' => $sRate,  

					'comments_count' => $aData['comments_count'],
					'created' => $this->filterDate ($aData['created']),
					'extend_created' => defineTimeInterval($aData['created']),
					 'all_categories' => $this->_oMain->parseCategories($aData['categories']),  
					'post_tags' => $this->_oMain->parseTags($aData['tags']), 		
					'school_description' => $sDesc,
					'flag_image' => genFlag($aData['country']), 
				),  		
			),  
		
		);        
 
        return $this->parseHtmlByName($sTemplateName, $aVars);
    }
 
    function mates ($aData, $sTemplateName, &$oVotingView) {
 
        if (null == $this->_oMain)
            $this->_oMain = BxDolModule::getInstance('BxSchoolsModule');
         
		$iAuthor = $aData['id_profile'];
		$aAuthor = getProfileInfo($iAuthor); 
		$sImage = $GLOBALS['oFunctions']->getMemberThumbnail($aAuthor['ID'], 'left'); 

    
        $aVars = array(  
			'id' => $aData['id'],
			'thumb_url' => $sImage ? $sImage : $this->getIconUrl('no-photo.png'), 
			'school_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aData['uri'],
			'school_title' => $aData['title'],
			'author' => getNickName($iAuthor),
			'author_url' => $iAuthor ? getProfileLink($iAuthor) : 'javascript:void(0);',
 			'country_city' => _t($GLOBALS['aPreValues']['Country'][$aData['country']]['LKey']) . (trim($aData['city']) ? ', '.$aData['city'] : ''), 
			'year_entered' => $aData['year_entered'],  
			'year_left' => ($aData['year_left']) ? $aData['year_left'] : _t('_modzzz_schools_present'),   
		);        
 
        return $this->parseHtmlByName('school_mates', $aVars);
    }

    function blockCustomFields (&$aDataEntry, $aShow=array()) {
        
		$bHasEntries = false;
	
		$sRet = '<table class="modzzz_schools_fields">';
        modzzz_schools_import ('FormAdd');        
        $oForm = new BxSchoolsFormAdd ($GLOBALS['oBxSchoolsModule'], $_COOKIE['memberID']);
        foreach ($oForm->aInputs as $k => $a) {
            //if (!isset($a['display'])) continue;
 
            if (!in_array($a['name'],$aShow)) continue;
            
			if (!trim($aDataEntry[$k])) continue;
			
			$bHasEntries = true;

            $sRet .= '<tr><td class="modzzz_schools_field_name" valign="top">'. $a['caption'] . '<td><td class="modzzz_schools_field_value">';
            
			if (is_string($a['display']) && is_callable(array($this, $a['display']))){
				//echo $a['listname'] .','.$aDataEntry[$k].'<br>';
                $sRet .= call_user_func_array(array($this, $a['display']), array($a['listname'],$aDataEntry[$k]));   
			}else{ 
				$sRet .= $aDataEntry[$k];
			}
            $sRet .= '<td></tr>';
        } 
        $sRet .= '</table>';
		
		if(!$bHasEntries) 
			return;
		else
			return $sRet;
    }

    function parseLink ($sName='', $sVal='') { 

		$sLink = (substr($sVal,0,3)=="www") ? "http://" . $sVal : $sVal; 
 
		return '<a href="'.$sLink.'" target=_blank>'.$sLink.'</a>';
	}
 
    function parsePreValues ($sName, $sVal='') {  
 		return htmlspecialchars_adv( _t($GLOBALS['aPreValues'][$sName][$sVal]['LKey']) );
 	}

    function parseMultiPreValues ($sName, $sVal='') {  
		$sStr = '';
		$aVals = split(';',$sVal);
		foreach($aVals as $aEachVal){
			if($GLOBALS['aPreValues'][$sName][$aEachVal]['LKey'])
 				$sStr .= htmlspecialchars_adv( _t($GLOBALS['aPreValues'][$sName][$aEachVal]['LKey'])) . '<br>';
			else
 				$sStr .= $aEachVal . '<br>'; 
		}
 		return $sStr;
 	}
 
    function filterDate ($i) {
        return getLocaleDate($i, BX_DOL_LOCALE_DATE) . ' ('.defineTimeInterval($i) . ')';
    } 
    //[end] - ultimate schools mod from modzzz 
 


}

?>
